{% extends 'dashboard/base.html' %}

{% block body %}

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">

    $("#checkAll").change(function () {
        $("input:checkbox").prop('checked', $(this).prop("checked"));
    });
    $(document).ready(function() {
        $("button").click(function(){
            var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
            $.each($("input[name='del_scan_id']:checked"), function(){
                scan_id.push($(this).val());
            });

            var json_scanid = scan_id.join(", ");
            $.ajax({
                type:'POST',
                <!--contentType: 'application/json; charset=utf-8',-->
                url:'/tools/nmap_scan_del/',
                data:{
                   ip_address: json_scanid,
                   csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
                },
                sucess:function(){

                }
            });
            setTimeout(function(){location.reload();},1000);
        });

    });






</script>

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="float-right">
                            <div class="btn-group" role="group" aria-label="Basic example">
                                <a href="{% url 'networkscanners:xml_upload' %}" class="btn btn-primary btn-mini"><i
                                        class="icon-upload-alt"></i> Upload XML</a>
                            </div>
                            <button type="button" class="btn btn-danger btn-mini" onclick="">Delete Selected</button>
                        </div>
                        <br>
                        <br>
                        <br>
                        <div class="d-md-flex align-items-center">
                            <h5 class="card-title">NMAP Scans Result</h5>
                        </div>
                        <br>
                        <div class="row">
                            <div class="table-responsive">
                                <!--<table id="data_table" class="table table-striped table-bordered" width="100%">-->
                                <table id="data_table" class="table table-bordered data-table">
                                    <thead>
                                    <tr>
                                        <!--<th><p><label><input type="checkbox" id="checkAll"/></label></p></th>-->
                                        <th><label class="customcheckbox m-b-20">
                                            <input type="checkbox" id="mainCheckbox">
                                            <span class="checkmark"></span>
                                        </label></th>
                                        <th>URL</th>
                                        <th>Total Ports</th>
                                        <th>Total Open Ports</th>
                                        <th>Total Close Ports</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>{% for data in all_nmap %}
                                    <tr data-target="#">
                                        <td>
                                            <form>
                                                <label class="customcheckbox">
                                                    <input type="checkbox" class="listCheckbox"
                                                           value="{{data.scan_ip}}"
                                                           name="del_scan_id"
                                                           onClick="reload">
                                                    <span class="checkmark"></span>
                                                </label>
                                            </form>
                                        </td>
                                        <td>
                                            {% if is_vulners %}
                                            <a href="/tools/nmap_vulners/?ip={{data.scan_ip}}">{{data.scan_ip}}</a>
                                            {% else %}
                                            <a href="/tools/nmap/?ip={{data.scan_ip}}">{{data.scan_ip}}</a>
                                            {% endif %}
                                        </td>
                                        <td>{{data.total_ports}}</td>
                                        <td>{{data.total_open_ports}}</td>
                                        <td>{{data.total_close_ports}}</td>
                                        <td>
                                            <form action="/tools/nmap_scan_del/" method="post" class="forms-sample">

                                                {% csrf_token %}
                                                <input type="hidden" name="ip_address" value="{{data.scan_ip}}"/>
                                                <button class="btn btn-danger"><i class="fas fa-times"></i></button>
                                            </form>
                                        </td>
                                        {% endfor %}
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

{% endblock %}
